package com.mycontract.suitepro.contract

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import com.mycontract.suitepro.base.BaseViewModel
import com.mycontract.suitepro.data.ReqBase
import com.mycontract.suitepro.data.ReqGetContractList
import com.mycontract.suitepro.data.ReqSignContract
import com.mycontract.suitepro.data.RevObjContractOrder
import com.mycontract.suitepro.network.ApiUserReposity

class ContractViewModel : BaseViewModel() {

    ////////
    private val mGetAppConfigLiveData = MutableLiveData<ReqBase>()

    val onGetAppConfigLiveData =
        Transformations.switchMap(mGetAppConfigLiveData) { query ->
            ApiUserReposity.getAppConfig(this, query)
        }

    fun getAppConfig(reqBase: ReqBase) {
        mGetAppConfigLiveData.value = reqBase
    }

    ////////
    val mContractOrderListTemp = mutableListOf<RevObjContractOrder>()
    val mContractOrderList = mutableListOf<RevObjContractOrder>()
    private val mGetContractOrderListLiveData = MutableLiveData<ReqGetContractList>()

    val onGetContractOrderListLiveData =
        Transformations.switchMap(mGetContractOrderListLiveData) { query ->
            ApiUserReposity.getContractOrderList(this, query)
        }

    fun getContractOrderList(reqGetContractList: ReqGetContractList) {
        mGetContractOrderListLiveData.value = reqGetContractList
    }

    ////////
    private val mSignContractLiveData = MutableLiveData<ReqSignContract>()

    val onSignContractLiveData =
        Transformations.switchMap(mSignContractLiveData) { query ->
            ApiUserReposity.signContract(this, query)
        }

    fun signContract(reqSignContract: ReqSignContract) {
        mSignContractLiveData.value = reqSignContract
    }
}